<?php
/**
 * Created by JetBrains PhpStorm.
 * User: FangXuanLing
 * Date: 13-11-19
 * Time: 下午3:35
 * To change this template use File | Settings | File Templates.
 */

class Category extends CActiveRecord{


    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
    //如果表名和模型名不一致，需要重写下该方法
    public function tableName()
    {
        return 'tbl_category';
    }

    //定义下主键
    public function primaryKey(){
        return "cid";
    }

    public function rules(){
        return array(
            array("category_name","required"),//category_name不能为空

        );
    }
    //定义表关系
    //参考：http://www.yiichina.com/guide/database.arr
    public function relations(){
        return array(
            'post'=>array(self::HAS_MANY,'Post','cid'),
        );
    }
}